-- UIDebug
-- Create by zouyb
-- 调试界面

--UIDebug继承自Layer
UIDebug = class("UIDebug", function() 
    return cc.Layer:create();
end);

function UIDebug.create()
    return UIDebug.new();
end    

function f()
    local UIHint = require "game/ui/dialog/UIHint";
    local hint = UIHint.create(getLocStr("get_loc_data"), false); 
    UIMgr.getCurrentScene():addDialog(hint);
end

--构造函数
function UIDebug:ctor()
    self:setName("UIDebug");

    --初始化
    local node = cc.CSLoader:createNode("layout/debug/Debug.csb");
    local action = cc.CSLoader:createTimeline("layout/debug/Debug.csb");
    node:runAction(action);
    self:addChild(node);  


    --"前往"按钮点击处理
    local gotoBtn = node:getChildByName("goto"); 
    local function onBtnClick(sender, eventType)
        if eventType == ccui.TouchEventType.ended then  
            local xLabel = node:getChildByName("input_x");
            local x = tonumber(xLabel:getString());

            local yLabel = node:getChildByName("input_y");
            local y = tonumber(yLabel:getString());         
         
			MapOp.gotoLocation(x, y);
        end
    end
    gotoBtn:addTouchEventListener(onBtnClick);
         
    --"关闭"按钮点击处理
    local closeBtn = node:getChildByName("close"); 
    local function onCloseClick(sender, eventType)
        if eventType == ccui.TouchEventType.ended then  
            UIMgr.getCurrentScene():removeForm(self);
        end
    end
    closeBtn:addTouchEventListener(onCloseClick);   
    
    --"录音"按钮点击处理
    local recordBtn = node:getChildByName("record"); 
    local function onRecordClick(sender, eventType)
        if eventType == ccui.TouchEventType.began then
            recordBtn:setTitleText("停止");
            callJavaFunc("startAudioRecord", {}, "()V");
        elseif eventType == ccui.TouchEventType.ended then
            recordBtn:setTitleText("录音");    
            callJavaFunc("stopAudioRecord", {}, "()V");
        end
    end
    recordBtn:addTouchEventListener(onRecordClick);  
    
    --"播放"按钮点击处理
    local path = cc.FileUtils:getInstance():getWritablePath() .. "/rec.mp3";
    
    local playBtn = node:getChildByName("play"); 
    local function onPlayClick(sender, eventType)
        if eventType == ccui.TouchEventType.ended then  
            AudioEngine.playMusic(path, false);
        end
    end
    playBtn:addTouchEventListener(onPlayClick);     
end



